#!/bin/bash
set -e
echo "Compiling rs-depth.c..."
gcc -c ../librealsense/examples/C/depth/rs-depth.c -I../librealsense/examples/C/ 

echo "Compiling SerialControl.cpp..."
g++ -c SerialControl.cpp -I. -Ilib/serial/include

echo "Compiling SerialControl_c.cpp..."
g++ -c SerialControl_c.cpp -I. -Ilib/serial/include

echo "Compiling capture_controller.c..."
gcc -c capture_controller.c -I. -Ilib/serial/include

echo "Creating directory structure if needed..."
mkdir -p pngs
mkdir -p depth_frames
mkdir -p color_frames

echo "Linking realsense application..."
g++ -o rsdc SerialControl.o SerialControl_c.o capture_controller.o rs-depth.o lib/serial/src/impl/list_ports/list_ports_linux.cc lib/serial/src/impl/unix.cc lib/serial/src/serial.cc -I. -Ilib/serial/include -lrealsense2 -lz -lpng -ljson-c -lpthread

echo "Compilation complete! Run ./rsdc to start capture"